
class Admin::BrandsController < Admin::BaseController

  def index
    @brands = Brand.paginate(page: params[:page] || 1, per_page: params[:per_page] || 15).order("id desc")
  end

  def new
    @brand = Brand.new
  end

  def create
    @brand = Brand.new(params.require(:brand).permit!)
    if @brand.save
      flash[:notice] = "新建品牌成功"
      redirect_to admin_brands_path
    else
      render action: :new
    end
  end

  def edit
    @brand = Brand.find params[:id]
    render action: :new
  end

  def update
    @brand = Brand.find params[:id]
    @brand.attributes = params.require(:brand).permit!

    if @brand.save
      flash[:notice] = "修改品牌成功"
      redirect_to admin_brands_path
    else
      render action: :new
    end
  end

end
